<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Widgets for displaying the event news stream.
 * Includes a list widget and its specific item widget.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.2
 * 
 * 0.2)  Inherited from the NewsStream and NewsStreamItem.
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_newsstream.php';

require_once INSTALLDIR . '/classes/User.php';
require_once INSTALLDIR . '/classes/EventNews.php';

/**
 * Widget for displaying a list of event news.
 */
class EventNewsStream extends NewsStream
{
	/**
	 * Overrided.
	 * Starts a news stream(list).
	 */
	function showStart()
	{
		$this->out->element('h3', null, '活动');
		$this->out->elementStart('ol', array('class' => 'cls_ol_list'));
		
		$this->out->element('hr');
	}
	
	/**
	 * Ends a list.
	 */
	function showEnd()
	{
		$this->out->elementEnd('ol');
	}
	
	/**
	 * Overrided.
	 * Returns a new stream item for the current sub news.
	 */
	function newListItem(&$subnews)
	{
		return new EventNewsStreamItem($subnews, $this->out);
	}
}

/**
 * Widget for displaying a single event news item with some buttons.
 */
class EventNewsStreamItem extends NewsStreamItem
{
	/**
	 * Overrided.
	 */
	function showStart()
	{
		$this->out->elementStart('li', array('class' => 'cls_div_entry'));
	}
	
	function showEnd()
	{
		$this->out->elementEnd('li');
		
		$this->out->element('hr');
	}
	
	/**
	 * Overrided.
	 */
	function showDataInfo()
	{
		$hasPoster = false;
		// Check if has a posted poster.
		if ( !empty($this->subnews->poster_id)) {
		// Get the poster' thumbnail url.
			$poster = Poster::staticGet('id', $this->subnews->poster_id);
			if ( !empty($poster)) {
				$hasPoster = true;
				$this->out->elementStart('div', array('class'	  => 'cls_div_poster',
													  'max-width' => POSTER_DOUBLE_SIZE,
												 	  'max-height'=> POSTER_MAX_HIGHT));
				$this->out->elementStart('a', array('href' => slh_action2url('event', 
																			 array('gnews_id' => $this->subnews->news_id)),
													'target' => '_blank'));
				$this->out->element('img', array('src' => $poster->thumbnailurl()));
				$this->out->elementEnd('a');
				$this->out->elementEnd('div');
			}
		}
		
		if ($hasPoster) {
			$this->out->elementStart('div', array('class' => 'cls_div_eventinfowithposter'));
		} else {
			$this->out->elementStart('div', array('class' => 'cls_div_eventinfo'));
		}
		$this->out->raw('<span class="cls_span_title">' .
						'<a target="_blank" href="' .
						slh_action2url('event', array('gnews_id' => $this->subnews->news_id)) .
						'">' . 
						$this->subnews->title . 
						'</a>' . 
						'</span>');
						
		$this->out->elementStart('div', array('class' => 'cls_div_eventmessage'));
		$this->out->raw('<span class="cls_span_message">' .
						$this->subnews->message . 
						'</span>');
		$this->out->elementEnd('div');
		$this->out->elementEnd('div');
		
		$this->out->raw('<span class="cls_span_onelineitem">' .
						'开始: ' .
						$this->subnews->started .
					   	$this->subnews->tagStarttime() .
						'</span>');
						
		$this->out->raw('<span class="cls_span_onelineitem">' .
						'结束: ' .
						$this->subnews->ended .
						'<span class="cls_span_red">' .
					   	$this->subnews->tagEndtime() .
					   	'</span>' .
						'</span>');
						
		$this->out->raw('<span class="cls_span_onelineitem">' .
						'地点: ' .
						$this->subnews->address .
						'</span>');
						
// FIXME: Get the Associations or hosts?~
		$this->out->raw('<span class="cls_span_onelineitem">' .
						'主办: ' .
						$this->subnews->host .	// or getAssociation()?
						'</span>');
			
		$this->out->raw('<span class="cls_span_eventnewscreated">' .
						slh_date_string($this->subnews->created) .
						'</span>');
	}
	
	/**
	 * Overrided.
	 */
	function showOptions()
	{
		$this->out->elementStart('div', 'cls_div_eventnewsoptions');
		
// TODO: Check if has rights to delete or more options.
		$this->out->elementStart('ul', array('class' => 'cls_ul_inline'));
			if (true) {
			$this->out->elementStart('li');
			$this->out->element('a', array('href' => slh_action2url('deleteeventnews',
								  	   							  	array('gnews_id' => $this->subnews->news_id)),
										   'title'=> '把这个活动及新鲜事删掉哈!'),
								'删除');
			$this->out->elementEnd('li');
			}
			
			if (false) {
			$this->out->elementStart('li');
			$this->out->elementEnd('li');
			}
		$this->out->elementEnd('ul');
		
		$this->out->elementEnd('div');
	}
}

?>